package top.lyc829.zzl_android.ui.profile.follow;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;

import com.google.android.material.tabs.TabLayoutMediator;

import top.lyc829.zzl_android.R;
import top.lyc829.zzl_android.databinding.ActivityFollowBinding;
import top.lyc829.zzl_android.ui.profile.follow.base.FollowBaseFragment;
import top.lyc829.zzl_android.ui.profile.follow.team.FollowTeamFragment;
import top.lyc829.zzl_android.ui.profile.follow.user.FollowUserFragment;
import top.lyc829.zzl_android.ui.thing.dynamic.DynamicFragment;
import top.lyc829.zzl_android.ui.thing.follow.FellowFragment;
import top.lyc829.zzl_android.ui.thing.travels.TravelsFragment;

public class FollowActivity extends AppCompatActivity {

    ActivityFollowBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_follow);
        binding = ActivityFollowBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());


        // 点击返回箭头返回上一页
        binding.mTitleBarFollow.setLeftClickListener(v -> finish());


        int page = getIntent().getIntExtra("id", 0);
        int userId = getIntent().getIntExtra("na", 0);

        ViewPager2 viewPager2 = binding.viewPager2;
        viewPager2.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                if (position == 0) {
                    FollowUserFragment fragment1=new FollowUserFragment();
                    fragment1.setOtherUserId(userId);
                    return fragment1;
                } else if (position == 1) {
                    FollowBaseFragment fragment2=new FollowBaseFragment();
                    fragment2.setotherUserId(userId);
                    return fragment2;

                } else {
                    FollowTeamFragment fragment3=new FollowTeamFragment();
                    fragment3.setOtheruserId(userId);
                    return fragment3;

                }
            }

            @Override
            public int getItemCount() {
                return 3;
            }
        });

        viewPager2.setCurrentItem(page);

        TabLayoutMediator mediator = new TabLayoutMediator(binding.tabLayout, viewPager2, ((tab, position) -> {
            if (position == 0) {
                tab.setText("关注的用户");
            } else if (position == 1) {
                tab.setText("关注的基地");
            } else if (position == 2) {
                tab.setText("关注的团队");
            }
        }));

        mediator.attach();

    }
}